﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../Content/highlighter/styles/shCoreDefault.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>log4net的手动配置</h3>
    <pre class="brush:csharp;">
    //配置文件的名称
    string log4netFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "server.log4net");
    //创建一个放配置的仓库
    var repository = LogManager.CreateRepository("server");
    //加载xml格式的配置文件到仓库中
    XmlConfigurator.Configure(repository,new FileInfo(log4netFileName));
    //从仓库中取出配置文件
    ILog log = LogManager.GetLogger("server", "FileAppender");
    </pre>
    //文本日志的配置，其它配置可查看官网
    <pre class="brush:csharp;">
        &lt;?xml version="1.0" encoding="utf-8" ?>
        &lt;log4net>
            &lt;appender name="FileAppender" type="log4net.Appender.FileAppender">
            &lt;file value="log-file.txt" />

            &lt;appendToFile value="true" />

            &lt;layout type="log4net.Layout.PatternLayout">
            &lt;conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />

		        &lt;/layout>
	        &lt;/appender>
            &lt;root>
            &lt;level value="DEBUG" />

            &lt;appender-ref ref="FileAppender" />

	        &lt;/root>
        &lt;/log4net>
    </pre>
</body>
</html>